app.controller("specificationController",function($scope,$controller,specificationService){

    $controller("baseController",{$scope:$scope});
    $scope.searchEntity={};
    $scope.list=[];
    $scope.entity={tbSpecification:{},tbSpecificationOptions:[]};
    $scope.search = function(page,rows){
        // 当前第几页    每页多少条
        specificationService.findPage(page,rows,$scope.searchEntity).then(function(result){
            $scope.list = result.data.rows;
            $scope.pageModel.totalItems = result.data.total;
        });
    }

    //添加一行
    $scope.addOption = function(){

        $scope.entity.tbSpecificationOptions.push({});
    }
    $scope.delOption = function($index){
        $scope.entity.tbSpecificationOptions.splice($index,1);
    }

    $scope.save = function(){
        if($scope.entity.tbSpecification.id){
            specificationService.update($scope.entity).then(function(result){
                if(result.data.success){
                    //刷新列表
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            })
        }else{
            specificationService.save($scope.entity).then(function(result){
                if(result.data.success){
                    //刷新列表
                    $scope.reloadList();
                }else {
                    alert(result.data.message);
                }
            });
        }

    }

    $scope.edit=function(id){
        specificationService.findOne(id).then(function (result) {
            $scope.entity=result.data;
            console.log($scope.entity);
        })
    }

    $scope.del = function(){
        specificationService.del($scope.selectedIds).then(function(result){
            if(result.data.success){
                $scope.reloadList();
            }else{
                alert(result.data.message);
            }
        })
    }
});